function calculaTotal_EAT() {

	val1 = document.getElementById('energia').value;
	val2 = document.getElementById('agua').value;
	val3 = document.getElementById('telecomunicacoes').value;
	res = (val1*1.0) + (val2*1.0) + (val3*1.0);	
	document.getElementById('EAT_total').value = FormatNumber(res,2,false,false,true);

}

function calculaTotal_FP() {

	val1 = document.getElementById('salarios').value;
	val2 = document.getElementById('decimo_terceiro_salario').value;
	val3 = document.getElementById('ferias').value;
	val4 = document.getElementById('rescisao_contrato').value;
	val5 = document.getElementById('pro_labore').value;
	val6 = document.getElementById('prestacoes_servicos').value;
	val7 = document.getElementById('folha_pagamento_outros_valores').value;
	res = (val1*1.0) + (val2*1.0) + (val3*1.0) + (val4*1.0) + (val5*1.0) + (val6*1.0) + (val7*1.0);
	document.getElementById('FP_total').value = FormatNumber(res,2,false,false,true);

}

function calculaTotal_ECDT() {

	val1 = document.getElementById('inss').value;
	val2 = document.getElementById('fgts').value;
	val3 = document.getElementById('contribuicao_sindical').value;
	val4 = document.getElementById('mensalidade_sindical').value;
	val5 = document.getElementById('taxa_assistencial').value;
	val6 = document.getElementById('irpj').value;
	val7 = document.getElementById('csll').value;
	val8 = document.getElementById('pis').value;
	val9 = document.getElementById('cofins').value;
	val10 = document.getElementById('simples').value;
	val11 = document.getElementById('irrf').value;
	val12 = document.getElementById('icms').value;
	val13 = document.getElementById('cpmf_iof_ioc').value;
	val14 = document.getElementById('iss').value;
	val15 = document.getElementById('iptu_ipva').value;
	val16 = document.getElementById('alvara_localizacao').value;
	val17 = document.getElementById('ECDT_outros_valores').value;
	res = (val1*1.0) + (val2*1.0) + (val3*1.0) + (val4*1.0) + (val5*1.0) + (val6*1.0) + (val7*1.0) + (val8*1.0) + (val9*1.0) + (val10*1.0) + (val11*1.0) + (val12*1.0) + (val13*1.0) + (val14*1.0) + (val15*1.0) + (val16*1.0) + (val17*1.0);
	document.getElementById('ECDT_total').value = FormatNumber(res,2,false,false,true);

}

function calculaTotal_Total() {

	val1 = document.getElementById('EAT_total').value;
	val2 = document.getElementById('FP_total').value;
	val3 = document.getElementById('aluguel').value;
	val4 = document.getElementById('ECDT_total').value;
	res = (val1*1.0) + (val2*1.0) + (val3*1.0) + (val4*1.0);	
	document.getElementById('total').value = FormatNumber(res,2,false,false,true);

}

function FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.
 
	RETVAL:
		The formatted number!
 **********************************************************************/
{ 
        if (isNaN(parseInt(num))) return "NaN";

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// Get sign of number
	
	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;					// Readjust for sign
	
	
	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);

	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
		if (num > 0)
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
		else
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
		
	// See if we need to put in the commas
	if (bolCommas && (num >= 1000 || num <= -1000)) {
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart >= 1) {
			tmpNumStr = tmpNumStr.substring(0,iStart) + tmpNumStr.substring(iStart,tmpNumStr.length)
			iStart -= 3;
		}		
	}

	// See if we need to use parenthesis
	if (bolParens && num < 0)
		tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";

	return tmpNumStr;		// Return our formatted string!
}